import {
	Config
} from "./Config.js"

const Language = {}
Language.languagePackage = require("../../static/language/" + Config.languagePackage + ".json");

Language.Get = (keyName, tipName, ...args) => {
	let str = Language.languagePackage[keyName][tipName].format(args);
	return str;
}

String.prototype.replaceAll = function(exp, newStr) {
	return this.replace(new RegExp(exp, "gm"), newStr);
};

String.prototype.format = function(args) {
	var result = this;
	if (arguments.length < 1) {
		return result;
	}

	var data = arguments;
	if (arguments.length == 1 && typeof(args) == "object") {
		data = args;
	}
	for (var key in data) {
		var value = data[key];
		if (undefined != value) {
			result = result.replaceAll("\\{" + key + "\\}", value);
		}
	}
	return result;
}

export {
	Language
}
